package Two;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;

@WebServlet("/register")
public class Register extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("get------------------");
        String paramsStr = req.getQueryString();
        String[] paramsArr = paramsStr.split("&");

        String username = paramsArr[0].split("=")[1];
        String password = paramsArr[1].split("=")[1];
        String gender = paramsArr[2].split("=")[1];
        String hobby = paramsArr[3].split("=")[1];

        System.out.println("用户名" + username);
        System.out.println("密码" + password);
        System.out.println("性别" + gender);
        System.out.println("爱好" + hobby);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        System.out.println("post-----------");

        Map<String,String[]> paramMap = req.getParameterMap();
        Set<String> keySet = paramMap.keySet();
        for(String key:keySet){
            System.out.println(key + "==" + Arrays.toString(paramMap.get(key)));
        }
    }
}
